package com.org.controller.change;

import com.org.entity.Poem;
import com.org.service.PoemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @author Rainy-Heights
 * @version 1.0
 * @Date 2023/3/11 20:26
 */
@Controller
@RequestMapping("/change")
public class ChangePoemController {
    @Resource
    PoemService poemService;

    @RequestMapping("/poem")
    public String Poem(Model model){
        Poem poem=poemService.getPoem();
        model.addAttribute("randomPoem",poem.getContent());
        model.addAttribute("authorName",poem.getAuthor());
        model.addAttribute("title",poem.getTitle());
        model.addAttribute("poem_count",poemService.getPoemCount());
        model.addAttribute("poem",poemService.getContentPoems());
        return "poem";
    }

    //增加诗歌
    @RequestMapping("/add")
    public String addPoem(){
            return " ";
    }
    //删除诗歌操作
    @RequestMapping("/delete")
    public String deletePoem(@ModelAttribute("update")Poem poem){
        if (poemService.deletePoem(poem.getId())>0){
            return "redirect:/change/poem";
        }
        return "error/pages-404";
    }
}
